package com.kangfawei.thread;

public class PriorityDemo implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            System.out.println(Thread.currentThread().getName() + "-->" + Thread.currentThread().getPriority());
        }
    }

    public static void main(String[] args){
        PriorityDemo pd = new PriorityDemo();
        Thread t1 = new Thread(pd,"A");
        Thread t2 = new Thread(pd,"B");
        Thread t3 = new Thread(pd,"C");
        Thread t4 = new Thread(pd,"D");
        Thread t5 = new Thread(pd,"E");
        Thread t6 = new Thread(pd,"F");
        // 先设置优先级再启动线程
        t1.setPriority(Thread.MAX_PRIORITY);
        t2.setPriority(Thread.MIN_PRIORITY);
        t3.setPriority(Thread.MIN_PRIORITY + 2);
        t4.setPriority(Thread.MIN_PRIORITY + 1);
        t5.setPriority(Thread.MAX_PRIORITY - 2);
        t6.setPriority(Thread.NORM_PRIORITY);

        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();
        t6.start();
    }
}
